package com.huhu.response;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;

import org.codehaus.jackson.map.annotate.JsonSerialize;

//返回不是节点不为null的json格式的文件
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class Response<T> implements Serializable {

	private int status;// 表示状态，1表示获取成功，0表示获取失败
	private T data;
	private String message;
	private HttpServletRequest request;
	

	private Response(int status, T data) {
		this.status = status;
		this.data = data;

	}

	private Response(int status, String message) {
		this.status = status;
		this.message = message;
	}
	
	private Response(int status, HttpServletRequest request) {
		this.status = status;
		this.request = request;
	}
	

	public int getStatus() {
		return status;
	}

	public T getData() {
		return data;
	}
	
	public String getMessage() {
		return message;
	}
	

	// success constructor
	public static <T> Response<T> searchBysuccess(T data) {
		return new Response<>(1, data);
	}
	
	public static <T> Response<T> searchBysuccess(HttpServletRequest request) {
		return new Response<>(1, request);
	}
	
	public static <T> Response<T> searchBysucessMessage(String message){
		return new Response<>(1, message);
	}

	// error
	public static <T> Response<T> searchByerror(String message) {
		return new Response<T>(0, message);
	}

}
